package com.csu.outlay;

import java.util.List;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.csu.dao.OutlayDao;
import com.csu.dao.OutlayDaoImpl;

public class NewFrame extends JFrame{
	public void initContent(){

		JLabel moneyLabel = new JLabel("支出金额:");
		//设置坐标和宽高
		moneyLabel.setBounds(60, 20, 80, 40);
		JTextField moneyField = new JTextField();
		moneyField.setBounds(140,20,250,40);
		JPanel panel1 = new JPanel();
		//将文本框和输入框加入到面板里
		panel1.add(moneyLabel);
		panel1.add(moneyField);
		panel1.setLayout(null);

		JLabel typeLabel = new JLabel("支出类型:");
		//设置坐标和宽高
		typeLabel.setBounds(60, 20, 80, 40);
		JComboBox<String> typeBox = new JComboBox<String>();
		String shop= "购物";
		String food="饮食";
		String live="住房";
		String travel="出行";
		String entertainment="娱乐";
		String medical="医疗";
		String other = "其他";
		typeBox.addItem(shop);
		typeBox.addItem(food);
		typeBox.addItem(live);
		typeBox.addItem(travel);
		typeBox.addItem(medical);
		typeBox.addItem(entertainment);
		typeBox.addItem(other);
		typeBox.setSelectedItem(shop);
		typeBox.setBounds(140,20,250,40);
		JPanel panel2 = new JPanel();
		//将文本框和输入框加入到面板里
		panel2.add(typeLabel);
		panel2.add(typeBox);
		panel2.setLayout(null);

		JLabel peopleLabel = new JLabel("支出者:");
		//设置坐标和宽高
		peopleLabel.setBounds(60, 20, 80, 40);
		JTextField peopleField = new JTextField();
		peopleField.setBounds(140,20,250,40);
		JPanel panel3 = new JPanel();
		//将文本框和输入框加入到面板里
		panel3.add(peopleLabel);
		panel3.add(peopleField);
		panel3.setLayout(null);

		JLabel dateLabel = new JLabel("支出日期:");
		//设置坐标和宽高
		dateLabel.setBounds(60, 20, 80, 40);
		JTextField dateField = new JTextField();
		dateField.setBounds(140,20,250,40);
		JPanel panel4 = new JPanel();
		//将文本框和输入框加入到面板里
		panel4.add(dateLabel);
		panel4.add(dateField);
		panel4.setLayout(null);

		JLabel useLabel = new JLabel("支出用途:");
		//设置坐标和宽高
		useLabel.setBounds(60, 20, 80, 40);
		JTextField useField = new JTextField();
		useField.setBounds(140,20,250,40);
		JPanel panel5 = new JPanel();
		//将文本框和输入框加入到面板里
		panel5.add(useLabel);
		panel5.add(useField);
		panel5.setLayout(null);

		JLabel notesLabel = new JLabel("相关备注:");
		//设置坐标和宽高
		notesLabel.setBounds(60, 20, 80, 40);
		JTextField notesField = new JTextField();
		notesField.setBounds(140,20,250,40);
		JPanel panel6 = new JPanel();
		//将文本框和输入框加入到面板里
		panel6.add(notesLabel);
		panel6.add(notesField);
		panel6.setLayout(null);

		JButton btnSubmit = new JButton("提交");
		JButton btnReset = new JButton("重置");
		JPanel panel7 = new JPanel(new FlowLayout(FlowLayout.CENTER));
		panel7.add(btnSubmit);
		panel7.add(btnReset);

		btnSubmit.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				//String moneyStr = moneyField.getText();
				double moneyStr = Double.valueOf(moneyField.getText());
				String typeStr = typeBox.getSelectedItem().toString();
				String peopleStr = peopleField.getText();
				String dateStr = dateField.getText();
				String useStr = useField.getText();
				String notesStr = notesField.getText();
				OutlayDao outlayDao = new OutlayDaoImpl();
				outlayDao.addOutlay(moneyStr, typeStr, peopleStr, dateStr, useStr, notesStr);
				initContent();
				//隐藏窗口
				setVisible(false);
				SubFrame subFrame = new SubFrame();
				subFrame.setSize(300, 150);
				subFrame.setLocationRelativeTo(null);
				subFrame.initContent();
			}
		});

		btnReset.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				moneyField.setText("");
				typeBox.setSelectedItem(shop);
				peopleField.setText("");
				dateField.setText("");
				useField.setText("");
				notesField.setText("");

			}

		});

		//创建垂直排列的容器Box
		Box vBox = Box.createVerticalBox();
		vBox.add(panel1);
		vBox.add(panel2);
		vBox.add(panel3);
		vBox.add(panel4);
		vBox.add(panel5);
		vBox.add(panel6);
		vBox.add(panel7);
		//jframe设置内容面板
		setContentPane(vBox);
		//显示窗口
		setVisible(true);

	}

}
